package Shopping;

import java.util.ArrayList;

public class ShoppingCart extends product{
	public int num;
	public double sum;
	public ShoppingCart(String name,double price,int num,double sum) {
		super(name,price);
		this.num = num;
		this.sum = sum;
	}

	public int getNum() {
		return num;
	}

	public void setNum(int num) {
		this.num = num;
	}

	public double getSum() {
		return sum;
	}

	public void setSum(double sum) {
		this.sum = sum;
	}

	@Override
	public String toString() {
		return "ShoppingCart [name=" + name + ", price=" + price + ", num=" + num  +", sum=" + sum + ", id="  + "]";
	}
	ArrayList <ShoppingCart> Goods = new ArrayList<ShoppingCart>();
	
	public boolean addShoppingCart(ShoppingCart goods){
		Goods.add(goods);
		return true;
	}
	public double sumShoppingCart(){
		double sum = 0;
		for(ShoppingCart goods:Goods){
			sum+=goods.getPrice()*goods.getNum();
		}
		return sum;
	}
	public boolean deleteShoppingCart(int index){
		if(index>=0&&index<Goods.size()){
			ShoppingCart goods;
			goods=Goods.get(index); 
			sum-=goods.getPrice()*goods.getNum();
			Goods.remove(index);
			return true;
		}
		else
			return false;
	}
}

